<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/common/easycommon.jsp" %>
<!DOCTYPE html>
<html>
<head>
  <title>系统字段</title>
  <meta charset="utf-8">
  <style>
    table {
      font-size: 14px
    }
    a{
      text-decoration:none;
    }

  </style>
  <script>
    $(function () {
      var editRow = undefined; //定义全局变量：当前编辑的行
      var clickRow = undefined;
      var treegrid = $('#dataTable').treegrid({
        fit: true, //treegrid自适应宽度
        fitColumn: false, //列自适应宽度
        //striped: true, //行背景交换
        //nowap: true, //列内容多时自动折至第二行
        //border: false,
        treeField: 'name',
        idField: 'id', //主键
        url: "${path}/syscolumn/queryDataList",
		columns:[[
					{field:'id', title: '编号', sortable: true, checkbox: true,fitColumns:true },
					{field:'name',title:'名字',width:'25%',fitColumns:true ,editor:{ type: 'validatebox', options: { required: true} }},
					{field:'sort',title:'排序',width:'25%',fitColumns:true ,editor:{ type: 'numberbox',options: { required: true} }},
					{field:'type',title:'类型',width:'25%',fitColumns:true ,
						editor:{ 
								type: 'combobox',
								required: true,
								options:
								{
									valueField: 'code',
									textField: 'name',
									url: '${path}/common/getBaseCodeList?type=coo_task_column_type'
								}
						},
						formatter: function(value,row,index) {    
			                 return row['typeName'];  
			             }			
					},
					{field:'itemType',title:'格式类型',width:'25%',fitColumns:true ,
					editor:{ 
							type: 'combobox',
							required: true,
							options:
							{
								valueField: 'code',
								textField: 'name',
								url: '${path}/common/getBaseCodeList?type=coo_task_column_itemtype'
							}
					},
					formatter: function(value,row,index) {    
		                 return row['itemTypeName'];  
		             }			
					}
				]],
				toolbar: [{ text: '添加', iconCls: 'icon-add', handler: function () {//添加列表的操作按钮添加，修改，删除等
		            //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑

		            if (editRow != undefined) {
		            	treegrid.treegrid("endEdit", editRow);
		            }
		            //添加时如果没有正在编辑的行，则在treegrid的第一行插入一行
		            if (editRow == undefined) {
		            	treegrid.treegrid("append", {
		            		parent:clickRow,
		            		data:[{
		            			id:'0',
		            			parentid:clickRow
		            		}]
		            	});
		            }
		                //将新插入的那一行开户编辑状态
		                treegrid.treegrid("beginEdit", '0');
		                //给当前编辑的行赋值
		                editRow = '0';           
		            }
		        }, '-',
		         { text: '删除', iconCls: 'icon-remove', handler: function () { 
		             if (clickRow !=null ) {
		             			$.ajax({
		               			 	url: "${path}/syscolumn/delSysColumn",    //请求的url地址
		               			 	dataType: "json",   //返回格式为json
		               			 	async: true, //请求是否异步，默认为异步，这也是ajax重要特性
		               			 	data: { "id":clickRow},    //参数值
		               			 	type: "post",   //请求方式
		               			 	success: function(req) {
		               			 		if(req.status=='1'){
		               			 			treegrid.treegrid("reload");	
		               			 		}else{
		               			 			$.messager.alert("提示", req.msg,"info"); 
		               			 		}                			 		
		            				},
		            				error:function(req) {
		            					console.log(req);
		            					$.messager.alert("警告", "删除出错","error"); 
		            				}
		            		});
		     
		             }else {
		                 $.messager.alert("提示", "请选择要删除的行", "error");
		             }
		         }
		         }, 
		         '-',
		         { text: '保存', iconCls: 'icon-save', handler: function () {
		             //保存时结束当前编辑的行，自动触发onAfterEdit事件如果要与后台交互可将数据通过Ajax提交后台
		             treegrid.treegrid("endEdit", editRow);
		         }
		         }, '-',
		         { text: '取消编辑', iconCls: 'icon-redo', handler: function () {
		             //取消当前编辑行把当前编辑行罢undefined回滚改变的数据,取消选择的行
		             editRow = undefined;
		             treegrid.treegrid("rejectChanges");
		             treegrid.treegrid("unselectAll");
		         	}
		         }
		         ],
    
		        onAfterEdit: function (row,changes) {
		            //endEdit该方法触发此事件
		            editRow = undefined;

		            row.children = undefined;
		            var rowStr=JSON.stringify(row);
		           // debugger;
		            if(row != null&&!$.isEmptyObject(changes)){
		     			$.ajax({
		       			 	url: "${path}/syscolumn/sysColumn",    //请求的url地址
		       			 	dataType: "json",   //返回格式为json
		       			 	async: true, //请求是否异步，默认为异步，这也是ajax重要特性
		       			 	data: rowStr,//{ "courseTextbook":courseTextbook },    //参数值
		       			 	type: "post",   //请求方式
		       			    contentType:'application/json',
		       			 	success: function(req) {
		       			 		if(req.status=='1'){
		       			 		treegrid.treegrid("reload");	
		       			 		}else{
		       			 			$.messager.alert("提示", req.msg,"info"); 
		       			 		}                			 		
		    				},
		    				error:function(req) {
		    					console.log(req);
		    					$.messager.alert("警告", "修改出错","error"); 
		    				}
		    			})
		        	
		            }

		        },

		        onDblClickRow: function (row) {
		        //双击开启编辑行h\

		            if (editRow != undefined) {
		            	treegrid.treegrid("endEdit", editRow);
		                editRow=undefined;
		            }
		            if (editRow == undefined) {
		            	treegrid.treegrid("beginEdit", row['id']);
		            	editRow = row['id'];  
		            }
		        },
		        onClickRow: function (row) {
		        	clickRow=row['id'];
			    }
      });
    })

    /*  function formatOper(val, row, index) {
      return '<a href="#" onclick="tablePop(' + index + ')">查看</a>   ';
    }

    //查询
   function searchFun(){
      var options = $('#dataTable').treegrid('options');
      //options.url = '${path}/report/khfxGridData';
      //options.queryParams = { dateYear: $('#querydate').val()};
      $('#dataTable').treegrid(options);
    }

    var layIndex;
    //查看扩展信息
    function tablePop(index){
      //$('#dataTable').treegrid('selectRow', index);
      var row = $('#dataTable').treegrid('getSelected');
      console.log(row);
      if (row.id&&row.taskUserId) {
        var url = "${path}/cootasktable/show?fTaskHeadid="+row.id+"&fTaskUserid="+row.taskUserId;
        url = decodeURI(url);
        layIndex = layer.open({
          title:"扩展信息",
          type: 2,
          fix: false,
          maxmin: true,
          area: ['880px', '670px'],
          content: url,
          cancel: function(index){
			
          }
        });
      } else {
        $.messager.alert("提示", "请先选择一条记录", "error");
      }
    } */
  </script>
</head>
<body>
<!-- style="width:850px;height:450px" -->
<table id="dataTable" title="系统字段" class="easyui-treegrid" 
       iconCls="icon-save">
</table>
</body>
</html>
